#include<iostream>
using namespace std;
int n;
const int len=2e5+10;
const int deep=-1e4-10;
int arr[len];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>arr[i];
    int i=1;
    int maxn=deep;
    while(i<=n){
        int temp=0;
        int j;
        for(j=i;j<=n;j++){
            temp+=arr[j];
            maxn=max(temp,maxn);
            if(temp<0)break;
        }
        i=j+1;
    }
    cout<<maxn<<endl;
}